package ru.tulupov.exerunner;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Redirecting data from input stream to output stream
 * 
 * @author <a href="mailto:zhekka3@gmail.com">Eugene Tulupov</a>
 */
public class StreamAdapter extends Thread {
	private Scanner in;
	private PrintStream out;

	public StreamAdapter(InputStream is, OutputStream os) {
		this.in = new Scanner(is);
		this.out = new PrintStream(os);
	}

	public StreamAdapter(InputStream is, PrintStream ps) {
		this.in = new Scanner(is);
		this.out = ps;
	}

	@Override
	public void run() {

		while (in.hasNextLine()) {
			String line = in.nextLine();

			out.println(line);
			out.flush();
		}

		out.close();
	}
}
